import React, { Component } from 'react'
import axios from 'axios'
// 高阶组件
// 1. 属性代理
function high(Com) {
    return class NewCom extends Component {
        state = {
            pageInfo: {
                pageSize: 10,
                pageNum: 1
            }
        }
        fn = () => {
            console.log('我是公共的方法')
        }
        render() {
            const { pageInfo } = this.state
            return (
                <div className='high'>
                    <Com pageInfo = { pageInfo } fn = { this.fn }/>
                </div>
            )
        }
        // componentDidMount() {
        //     this.fn()
        // }
    }
}

function high2(Com, url) {
    return class NewCom extends Component {
        state = {
            list: [],
            total: 0
        }
        pageSizeChange = (page, pageSize) => {
            console.log(page, pageSize)
        }
        render() {
            const { total } = this.state
            return <div>
                <Com total = { total } pageSizeChange = { this.pageSizeChange }/>
            </div>
        }
        
        componentDidMount() {
            axios.get(url).then(res => {
                this.setState({
                    total: res.data.total
                })
            })
        }
    }
}

export {
    high,
    high2
}
